<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head xmlns:th="http://www.thymeleaf.org" th:include="master::head">
    <title>添加PageInfo</title>
</head>
<body>
<div class="container">
    <div class="row">
        <table class="table table-striped table-bordered table-condensed">
            <thead>目前支持的表达式语法(多个函数参数以$$代替,隔开)
            <tr>
            <th>函数名</th>
            <th>参数</th>
            <th>说明</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>constant</td>
                <td>一个常量</td>
                <td>添加一个常量字段</td>
            </tr>
            <tr>
                <td>customurl</td>
                <td>包含"REQUEST(参数名)"的字符串</td>
                <td>在Request上下文中查找”参数名“对应的值，并替换</td>
            </tr>
            <tr>
                <td>prefix</td>
                <td>字符串</td>
                <td>添加一个字符串前缀（如果是集合，则每个元素添加该前缀）</td>
            </tr>
            <tr>
                <td>suffix</td>
                <td>字符串</td>
                <td>添加一个字符串后缀（如果是集合，则每个元素添加该前缀）</td>
            </tr>
            <tr>
                <td>getjson</td>
                <td></td>
                <td>获取一个Json对象</td>
            </tr>
            <tr>
                <td>css</td>
                <td>一个或两个参数</td>
                <td>与WebMagic中的css函数一致</td>
            </tr>
            <tr>
                <td>replace</td>
                <td>(String regex, String replacement)</td>
                <td></td>
            </tr>
            <tr>
                <td>stringreplace</td>
                <td>(String oldStr, String newStr)</td>
                <td>支持Collection逐一替换</td>
            </tr>
            <tr>
                <td>xpath</td>
                <td>String</td>
                <td>与WebMagic中的xpath函数一致</td>
            </tr>
            <tr>
                <td>links</td>
                <td></td>
                <td>取所有链接</td>
            </tr>
            <tr>
                <td>regex</td>
                <td>一个或两个参数</td>
                <td>与WebMagic中的regex函数一致</td>
            </tr>
            <tr>
                <td>jsonpath</td>
                <td>String</td>
                <td>与WebMagic中的jsonpath函数一致</td>
            </tr>
            <tr>
                <td>all</td>
                <td></td>
                <td>与WebMagic中的all函数一致</td>
            </tr>
            <tr>
                <td>get</td>
                <td></td>
                <td>与WebMagic中的get函数一致</td>
            </tr>
            </tbody>
        </table>
        <form class="form" action="saveUrlRule" method="post">
            <!--<div class="form-body">-->
            <div class="form-group">
                <input type="hidden" th:value="${pageId}" name="pageId"/>
                <label class="control-label">要测试的表达式</label>
                <input type="text" class="form-control" name="expression"
                       value="page.css(body)"/></div>
            <!--</div>-->
            <!--<div class="form-actions">-->
            <button id="btnTest" type="button" class="btn green test">测试</button>
            <!--</div>-->
        </form>
        <textarea class="testResult form-control " rows="7"></textarea>
    </div>

</div>
<script th:inline="javascript">
    /*<![CDATA[*/
    $(function () {
        $("#btnTest").click(function () {
            var form = $(this).closest("form");
            var data = {};
            form.serializeArray().map(function (x) {
                data[x.name] = x.value;
            });
            data.scope = "url";
            $.ajax({
                type: "post",
                cache: false,
//                contentType: "application/json",
                url: global.contextPath + "/testExpressionOnPage",
                data: data,
                dataType: 'text',
                success: function (result) {     //回调函数，result，返回值
                    $(".testResult").val(result);
                },
                error: function (msg) {
                    alert("测试出现异常！");
                    console.log(msg);
                }
            });
        });
    });

    /*]]>*/
</script>

</body>
</html>